package day1217;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ExamresultTest {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        ExamresultDao dao = new ExamresultDaoImpl();
        SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-mm-dd");//可以方便地修改日期格式
        int choice = 0;
        while (true) {
            System.out.println("1.增加成绩 2修改 3删除成绩 4查询全部  0退出");
            choice = input.nextInt();
            switch (choice) {
                case 1:
                    System.out.println("请输入考试时间");
                    String sj=input.next();
                    Date sj1 = null;
                    try {
                        sj1 = dateFormat.parse(sj);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    System.out.println("请输入考试分数");
                    Double fenshu=input.nextDouble();
                    System.out.println("请输入学生编号");
                    int stid=input.nextInt();
                    System.out.println("请输入课程编号");
                    int sbid=input.nextInt();
                    Examresult ex=new Examresult(sj1,fenshu,stid,sbid);
                    int a=dao.add(ex);
                    System.out.println(a);
                    break;
                case 2:
                    System.out.println("请输入要修改的id");
                    int id1=input.nextInt();
                    System.out.println("请输入考试时间");
                    String sj2=input.next();
                    Date sj3 = null;
                    try {
                        sj3 = dateFormat.parse(sj2);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    System.out.println("请输入考试分数");
                    Double fenshu2=input.nextDouble();
                    System.out.println("请输入学生编号");
                    int stid2=input.nextInt();
                    System.out.println("请输入课程编号");
                    int sbid2=input.nextInt();
                    Examresult ex2=new Examresult(id1,sj3,fenshu2,stid2,sbid2);
                    int a2=dao.update(ex2);
                    System.out.println(a2);
                    break;
                case 3:
                    System.out.println("请输入要删除的id");
                    int id3=input.nextInt();
                    int a3=dao.del(id3);
                    System.out.println(a3);
                    if (a3==1){
                        System.out.println("删除成功");
                    }
                    break;
                case 4:
                    List<Examresult> all = dao.all();
                    for (Examresult e : all)
                        System.out.println(e);
                    break;
                case 5:
                   break;
                case 6:

                    break;
                case 0:
                    return;
            }
        }
    }

}
